﻿@model IList<JLPT.Models.Objects.Question>
@using JLPT.Models.Objects
@using JLPT.Common
@{
    ViewBag.Title = "Test";
}
@{
    int counter = 0;
    int subCounter = 0;

    int noRight = @ViewBag.NoRight;
    int total = @ViewBag.Total;
}
<script type="text/javascript">
    $(document).ready(function () {
        
        $('[id^="Question"]').on("click", function () {
            questionId = this.id.split("-")[1];
            
            var model = {
                QuestionId: questionId,
                Favourite: $(this).attr("favorite")
            }
            $.ajax({
                type: "POST",
                url: "/Quiz/Favorite",
                data: model,
                success: function (data) {
                    if (data.favorite) {
                        $("#Question-" + questionId).append("<img src='/Content/Images/favorite.png'/>");
                        $("#Question-" + questionId).attr("favorite", true);
                    } else {
                        $("#Question-" + questionId).find("img").remove();
                        $("#Question-" + questionId).attr("favorite", false);
                    }
                }
            })

        })
    });

</script>

    <div style="padding:20px; border:1px solid #000">
        Result: @noRight/@total (@ViewBag.Percent%)
    </div>

    @for (int i = 0; i < Model.Count(); i++)
    {
        counter = i + 1;
        @Html.HiddenFor(x => x[i].Id)

        @Html.QuestionNameResult(counter, Model[i], true)

        for (int k = 0; k < Model[i].QuestionSubs.Count(); k++)
        {
            subCounter = k + 1;
            @Html.HiddenFor(x => x[i].QuestionSubs[k].Id)
            @Html.FormatSub(subCounter, Model[i].QuestionSubs[k]) 

            for (int j = 0; j < Model[i].QuestionSubs[k].QuestionDetails.Count(); j++)
            {
                @Html.HiddenFor(x => x[i].QuestionSubs[k].QuestionDetails[j].Id)
                <div style="margin-left:50px;">
                    @Html.RadioButtonFor(x => Model[i].QuestionSubs[k].SelectedAnswer, Model[i].QuestionSubs[k].QuestionDetails[j].Id, new { disabled = "disabled" }) 

                    @*@Model[i].QuestionSubs[k].QuestionDetails[j].Answer
                    @if (Model[i].QuestionSubs[k].QuestionDetails[j].IsRight)
                    {
                        <img src="~/Content/Images/right.png" />
                    }*@

                    @Html.WrongAnswer(Model[i].QuestionSubs[k].QuestionDetails[j], Model[i].QuestionSubs[k].SelectedAnswer)
                </div>
            }
        }
    }
    <p>&nbsp;</p>
    @Html.ActionLink("Another test","Index")

